home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / pc / files / t_unix / j109lxa4.tar / slhcdump.c < prev    next >
C/C++ Source or Header  |  1994-06-04  |  3KB  |  178 lines

  1. #include <stdio.h>
  2. #include "global.h"
  3. #include "mbuf.h"
  4. #include "internet.h"
  5. #include "ip.h"
  6. #include "slhc.h"
  7. #include "trace.h"
  8.  
  9. static int16 decodeint __ARGS((struct mbuf **bpp));
  10.  
  11. static int16
  12. decodeint(bpp)
  13. struct mbuf **bpp;
  14. {
  15.     char tmpbuf[2];
  16.  
  17.     pullup(bpp,tmpbuf,1);
  18.     if (tmpbuf[0] == 0)
  19.         pullup(bpp,tmpbuf,2);
  20.     else {
  21.          tmpbuf[1] = tmpbuf[0];
  22.         tmpbuf[0] = 0;
  23.     }
  24.     return(get16(tmpbuf));
  25. }
  26.  
  27. void
  28. #ifdef MONITOR
  29. vjcomp_dump(fp,bpp,unused,mon)
  30. #else
  31. vjcomp_dump(fp,bpp,unused)
  32. #endif
  33. FILE *fp;
  34. struct mbuf **bpp;
  35. int unused;
  36. #ifdef MONITOR
  37. int mon;
  38. #endif
  39. {
  40.     char changes;
  41.     char tmpbuf[2];
  42.  
  43.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  44.         return;    
  45.  
  46.     /* Dump compressed TCP/IP header */
  47.     changes = pullchar(bpp);
  48. #ifdef MONITOR
  49.     if (!mon)
  50. #endif
  51.     fprintf(fp,"\tchanges: 0x%02x",uchar(changes));
  52.     if (changes & NEW_C) {
  53.         pullup(bpp,tmpbuf,1);
  54. #ifdef MONITOR
  55.         if (!mon)
  56. #endif
  57.         fprintf(fp,"   connection: 0x%02x",uchar(tmpbuf[0]));
  58.     }
  59.     pullup(bpp,tmpbuf,2);
  60. #ifdef MONITOR
  61.     if (!mon)
  62. #endif
  63.     fprintf(fp,"   TCP checksum: 0x%04x",get16(tmpbuf));
  64.  
  65.     if (changes & TCP_PUSH_BIT)
  66. #ifdef MONITOR
  67.         if (!mon)
  68. #endif
  69.         fprintf(fp,"   PUSH");
  70.     fprintf(fp,"\n");
  71.  
  72. #ifdef MONITOR
  73.     /* regrettably, can't dump data from a compressed packet */
  74.     if (!mon)
  75.     {
  76. #endif
  77.     switch (changes & SPECIALS_MASK) {
  78.     case SPECIAL_I:
  79.         fprintf(fp,"\tdelta ACK and delta SEQ implied by length of data\n");
  80.         break;
  81.  
  82.     case SPECIAL_D:
  83.         fprintf(fp,"\tdelta SEQ implied by length of data\n");
  84.         break;
  85.  
  86.     default:
  87.         if (changes & NEW_U) {
  88.             fprintf(fp,"\tUrgent pointer: 0x%02x",decodeint(bpp));
  89.         }
  90.         if (changes & NEW_W)
  91.             fprintf(fp,"\tdelta WINDOW: 0x%02x",decodeint(bpp));
  92.         if (changes & NEW_A)
  93.             fprintf(fp,"\tdelta ACK: 0x%02x",decodeint(bpp));
  94.         if (changes & NEW_S)
  95.             fprintf(fp,"\tdelta SEQ: 0x%02x",decodeint(bpp));
  96.         break;
  97.     };
  98.     if (changes & NEW_I) {
  99.         fprintf(fp,"\tdelta ID: 0x%02x\n",decodeint(bpp));
  100.     } else {
  101.         fprintf(fp,"\tincrement ID\n");
  102.     }
  103. #ifdef MONITOR
  104. }
  105. #endif
  106. }
  107.  
  108.  
  109. /* dump serial line IP packet; may have Van Jacobson TCP header compression */
  110. void
  111. #ifdef MONITOR
  112. sl_dump(fp,bpp,unused,mon)
  113. #else
  114. sl_dump(fp,bpp,unused)
  115. #endif
  116. FILE *fp;
  117. struct mbuf **bpp;
  118. int unused;
  119. #ifdef MONITOR
  120. int mon;
  121. #endif
  122. {
  123.     struct mbuf *bp, *tbp;
  124.     unsigned char c;
  125.     int len;
  126.  
  127.     bp = *bpp;
  128.     c = bp->data[0];
  129.     if (c & SL_TYPE_COMPRESSED_TCP) {
  130. #ifdef MONITOR
  131.         if (mon)
  132.             fprintf(fp, "CSLIP ");
  133.         else
  134. #endif
  135.         fprintf(fp,"serial line VJ Compressed TCP: len %3u\n",
  136.             len_p(*bpp));
  137.         vjcomp_dump(fp,bpp,0,mon);
  138.     } else if ( c >= SL_TYPE_UNCOMPRESSED_TCP ) {
  139. #ifdef MONITOR
  140.         if (mon)
  141.             fprintf(fp, "VJSLIP "), len = len_p(bp);
  142.         else
  143. #endif
  144.         fprintf(fp,"serial line VJ Uncompressed TCP: len %3u\n",
  145.             len = len_p(bp));
  146.         /* Get our own copy so we can mess with the data */
  147.         if ( (tbp = copy_p(bp, len)) == NULLBUF )
  148. #ifdef MONITOR
  149.         {
  150.             fprintf(fp, "\n");
  151. #endif
  152.             return;
  153.  
  154. #ifdef MONITOR
  155.         }
  156.         if (mon)
  157.             fprintf(fp, "[%d] ", uchar(tbp->data[9]));
  158.         else
  159. #endif
  160.         fprintf(fp,"\tconnection ID = %d\n",
  161.             uchar(tbp->data[9]));    /* FIX THIS! */
  162.         /* Restore the bytes used with Uncompressed TCP */
  163.         tbp->data[0] &= 0x4f;        /* FIX THIS! */
  164.         tbp->data[9] = TCP_PTCL;    /* FIX THIS! */    
  165.         /* Dump contents as a regular IP packet */
  166.         ip_dump(fp,&tbp,1,mon);
  167.         free_p(tbp);
  168.     } else {
  169. #ifdef MONITOR
  170.         if (mon)
  171.             fprintf(fp, "SLIP ");
  172.         else
  173. #endif
  174.         fprintf(fp,"serial line IP: len: %3u\n",len_p(*bpp));
  175.         ip_dump(fp,bpp,1,mon);
  176.     }
  177. }
  178.